package org.msfj.hospital.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.msfj.common.base.BaseController;
import org.msfj.common.model.CascaderResult;
import org.msfj.common.model.CommonResult;
import org.msfj.hospital.model.HospitalDept;
import org.msfj.hospital.service.HospitalDeptService;
import org.msfj.hospital.vo.HospitalDeptVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 医院科室信息controller
 * @Author: like
 * @Email: like@deyatong.com
 * @Date: 2018-08-10 14:12:03
 * @Version: 1.0
 * @Created in idea by autoCode
 */
@Api(value = "医院科室信息接口", tags = "医院科室信息接口")
@RestController
@RequestMapping("/hospitalDept/")
public class  HospitalDeptController extends BaseController{

    @Autowired
    private HospitalDeptService hospitalDeptService;

    /**
     * 添加医院科室信息
     *
     * @param hospitalDeptVo
     * @return CommonResult.ok(HospitalDeptVo)
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加医院科室信息",notes = "添加医院科室信息")
    @ApiImplicitParam(value = "hospitalDeptVo",name = "hospitalDeptVo",dataType = "org.msfj.hospital.vo.HospitalDeptVo",paramType = "query")
    public CommonResult addHospitalDept(HospitalDeptVo hospitalDeptVo){
        HospitalDept hospitalDept = hospitalDeptService.saveOrEdit(hospitalDeptVo);
        return CommonResult.ok(hospitalDeptService.setOtherProperties(hospitalDept));
    }

    /**
     * 修改医院科室信息
     *
     * @param hospitalDeptVo
     * @return CommonResult.ok(HospitalDeptVo)
     */
    @PostMapping("/edit")
    @ApiOperation(value = "修改医院科室信息",notes = "修改医院科室信息")
    @ApiImplicitParam(value = "hospitalDeptVo",name = "hospitalDeptVo",dataType = "org.msfj.hospital.vo.HospitalDeptVo",paramType = "query")
    public CommonResult editHospitalDept(HospitalDeptVo hospitalDeptVo){
        HospitalDept hospitalDept = hospitalDeptService.saveOrEdit(hospitalDeptVo);
        return CommonResult.ok(hospitalDeptService.setOtherProperties(hospitalDept));
    }

    /**
     * 逻辑删除医院科室信息
     *
     * @param hospitalDeptVo
     * @return CommonResult.ok(HospitalDeptVo)
     */
    @PostMapping("/del")
    @ApiOperation(value = "逻辑删除医院科室信息",notes = "逻辑删除医院科室信息")
    @ApiImplicitParam(value = "hospitalDeptVo",name = "hospitalDeptVo",dataType = "org.msfj.hospital.vo.HospitalDeptVo",paramType = "query")
    public CommonResult delHospitalDept(HospitalDeptVo hospitalDeptVo){
        HospitalDept hospitalDept = hospitalDeptService.delById(hospitalDeptVo);
        return CommonResult.ok(hospitalDeptService.setOtherProperties(hospitalDept));
    }

    /**
     * 逻辑删除系统用户信息
     * @param ids
     * @return CommonResult.ok()
     */
    @PostMapping("/dels")
    @ApiOperation(value = "逻辑删除医院科室信息",notes = "逻辑删除医院科室信息")
    @ApiImplicitParam(value = "ids[]",name = "ids[]",dataType = "java.util.List",paramType = "query")
    public CommonResult delSysUsers(@RequestParam(value = "ids[]",required = false) List<String> ids){
        HospitalDept hospitalDept = new HospitalDept();
        hospitalDeptService.delByIds(ids,hospitalDept);
        return CommonResult.ok();
    }

    /**
     * 真实删除医院科室信息
     *
     * @param hospitalDeptVo
     * @return CommonResult.ok()
     */
    @PostMapping("/delete")
    @ApiOperation(value = "真实删除医院科室信息",notes = "真实删除医院科室信息")
    @ApiImplicitParam(value = "hospitalDeptVo",name = "hospitalDeptVo",dataType = "org.msfj.hospital.vo.HospitalDeptVo",paramType = "query")
    public CommonResult deleteHospitalDept(HospitalDeptVo hospitalDeptVo){
        hospitalDeptService.trueDelById(hospitalDeptVo);
        return CommonResult.ok();
    }

    /**
     * 根据id查找医院科室信息
     *
     * @param hospitalDeptVo
     * @return CommonResult.ok(HospitalDeptVo)
     */
    @GetMapping("/get")
    @ApiOperation(value = "根据id查找医院科室信息",notes = "根据id查找医院科室信息")
    @ApiImplicitParam(value = "hospitalDeptVo",name = "hospitalDeptVo",dataType = "org.msfj.hospital.vo.HospitalDeptVo",paramType = "query")
    public CommonResult getHospitalDept(HospitalDeptVo hospitalDeptVo){
        HospitalDept hospitalDept = hospitalDeptService.getById(hospitalDeptVo.getId());
        return CommonResult.ok(hospitalDeptService.setOtherProperties(hospitalDept));
    }

    /**
     * 根据翻页参数、搜索参数查找医院科室信息
     *
     * @param hospitalDeptVo
     * @param page 当前第几页
     * @param rows 每页多少条记录
     * @return CommonResult.ok(PageInfo<HospitalDeptVo>)
     */
    @GetMapping("/list")
    @ApiOperation(value = "根据翻页参数、搜索参数查找医院科室信息",notes = "根据翻页参数、搜索参数查找医院科室信息")
    @ApiImplicitParams({
        @ApiImplicitParam(value = "hospitalDeptVo",name = "hospitalDeptVo",dataType = "org.msfj.hospital.vo.HospitalDeptVo",paramType = "query"),
        @ApiImplicitParam(name = "page",value = "page",dataType = "Integer",paramType = "path"),
        @ApiImplicitParam(name = "rows",value = "rows",dataType = "Integer",paramType = "path")
    })
    public CommonResult findHospitalDeptList(HospitalDeptVo hospitalDeptVo, Integer page, Integer rows){
        PageInfo<HospitalDeptVo> hospitalDeptVoPageInfo = hospitalDeptService.getByHospitalDept(hospitalDeptVo,page,rows);
        return CommonResult.ok(hospitalDeptVoPageInfo);
    }

    /**
     * 根据搜索参数查找所有医院科室信息
     *
     * @param hospitalDeptVo
     * @return CommonResult.ok(List<HospitalDeptVo>)
     */
    @GetMapping("/getAll")
    @ApiOperation(value = "根据搜索参数查找所有医院科室信息",notes = "根据搜索参数查找所有医院科室信息")
    @ApiImplicitParam(value = "hospitalDeptVo",name = "hospitalDeptVo",dataType = "org.msfj.hospital.vo.HospitalDeptVo",paramType = "query")
    public CommonResult getAllHospitalDept(HospitalDeptVo hospitalDeptVo){
        List<HospitalDeptVo> hospitalDeptVoList = hospitalDeptService.getAllHospitalDept(hospitalDeptVo);
        return CommonResult.ok(hospitalDeptVoList);
    }

    /**
     * 获取医院科室信息Tree对象
     *
     * @return CommonResult.ok(List<HospitalDeptVo>)`
     */
    @GetMapping("/getTree")
    @ApiOperation(value = "获取医院科室信息Tree对象", notes = "获取医院科室信息Tree对象")
    public CommonResult getHospitalDeptTree() {
        List<HospitalDeptVo> hospitalDeptVos = hospitalDeptService.getHospitalDeptTree();
        return CommonResult.ok(hospitalDeptVos);
    }

    /**
     * 获取医院科室信息级联对象
     *
     * @param id  不可选的id
     * @return CommonResult.ok(List<CascaderResult>)
     */
    @GetMapping("/getCascader")
    @ApiOperation(value = "获取医院科室信息级联对象", notes = "获取医院科室信息级联对象")
    @ApiImplicitParam(value = "id", name = "id", dataType = "java.lang.Long", paramType = "query")
    public CommonResult getCascader(String id) {
        List<HospitalDeptVo> hospitalDeptVos = hospitalDeptService.getHospitalDeptTree();
        List<CascaderResult> cascaderResults = CascaderResult.getCascaderResult("Id", "Name","TreePosition", id,hospitalDeptVos);
        return CommonResult.ok(cascaderResults);
    }
}
